package com.liangplus.elasticsearch.controller;

import com.liangplus.elasticsearch.entity.eo.ShrEO;
import com.liangplus.elasticsearch.entity.eo.UserPEO;
import com.liangplus.elasticsearch.repository.ShrRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;


/**
 * Created by yumin on 2019/8/2.
 */
@Controller
@RequestMapping("/shr")
public class ShrController {

    @Autowired
    private ShrRepository shrRepository;

    @PostMapping
    @ResponseBody
    public String add(@RequestBody ShrEO shr) {
        shrRepository.save(shr);
        return "success";
    }

    @DeleteMapping(value = "/{id}")
    @ResponseBody
    public String delete(@PathVariable String id) {
        shrRepository.deleteById(id);
        return "success";
    }

    @GetMapping(value = "/{id}")
    @ResponseBody
    public ShrEO getById(@PathVariable String id) {
        Optional<ShrEO> shrEOOptional = shrRepository.findById(id);
        if (shrEOOptional.isPresent()) {
            ShrEO shrEO = shrEOOptional.get();
            return shrEO;
        }
        return null;
    }


}
